package com.iknow.xmpp.smack.pep;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.pubsub.EventElement;
import org.jivesoftware.smackx.pubsub.EventElementType;
import org.jivesoftware.smackx.pubsub.Item;
import org.jivesoftware.smackx.pubsub.ItemsExtension;
import org.jivesoftware.smackx.pubsub.ItemsExtension.ItemsElementType;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PubSubManager;

public class PepSubManager extends PubSubManager
{
  private PacketFilter mPacketFilter;
  private List<PEPListener> mPepListeners = new ArrayList();

  public PepSubManager(Connection paramConnection)
  {
    super(paramConnection);
    this.mPacketFilter = new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event");
    init(paramConnection);
  }

  public PepSubManager(Connection paramConnection, String paramString)
  {
    super(paramConnection, paramString);
    this.mPacketFilter = new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event");
    init(paramConnection);
  }

  private void firePEPListeners(String paramString1, String paramString2, List<Item> paramList)
  {
    Iterator localIterator = this.mPepListeners.iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
        return;
      ((PEPListener)localIterator.next()).eventReceived(paramString1, paramString2, paramList);
    }
  }

  private void init(Connection paramConnection)
  {
    paramConnection.addPacketListener(new PacketListener(this)
    {
      public void processPacket()
      {
        EventElement localEventElement = (EventElement)paramPacket.getExtension("event", "http://jabber.org/protocol/pubsub#event");
        if (localEventElement.getEventType() != EventElementType.items);
        while (true)
        {
          ItemsExtension localItemsExtension;
          do
          {
            return;
            localItemsExtension = (ItemsExtension)localEventElement.getEvent();
          }
          while (localItemsExtension.getItemsElementType() != ItemsExtension.ItemsElementType.items);
          List localList = localItemsExtension.getItems();
          PepSubManager.access$0(this.this$0, paramPacket.getFrom(), localItemsExtension.getNode(), localList);
        }
      }
    }
    , this.mPacketFilter);
  }

  public void addPEPListener(PEPListener paramPEPListener)
  {
    if (!(this.mPepListeners.contains(paramPEPListener)))
      this.mPepListeners.add(paramPEPListener);
  }

  public LeafNode getPEPNode(String paramString)
  {
    LeafNode localLeafNode = new LeafNode(this.con, paramString);
    localLeafNode.setTo(this.to);
    return localLeafNode;
  }

  public void removePEPListener(PEPListener paramPEPListener)
  {
    this.mPepListeners.remove(paramPEPListener);
  }
}